#include "cmd_gpio.h"
#include "drv_gpio.h"
#include <ctype.h>
rt_inline int cmd_atoi(const char **s)
{
    register int i = 0;
    while (isdigit(**s))
        i = i * 10 + *((*s)++) - '0';

    return i;
}

long setgpio(int argc, char**argv)
{
    int pin, value;
    if(argc < 2)
    {
        return -1;
    }
    pin = cmd_atoi((const char **)(&argv[1]));
    value = cmd_atoi((const char **)(&argv[2]));
    drv_hc32_pin_write(pin,value);
    return 0;
}
FINSH_FUNCTION_EXPORT(setgpio, setgpio setgpio: <num|value>);
MSH_CMD_EXPORT(setgpio, setgpio setgpio: <num|value>);
long cfggpio(int argc, char**argv)
{
    int pin,mode;
    if(argc < 2)
    {
        return -1;
    }
    pin = cmd_atoi((const char **)(&argv[1]));
    if(!rt_strcmp(argv[2],"output"))
    {
       mode = PIN_MODE_OUTPUT;
    }
    if(!rt_strcmp(argv[2],"input"))
    {
       mode = PIN_MODE_INPUT;
    }
    drv_hc32_pin_mode(pin,mode);
    return 0;
}
FINSH_FUNCTION_EXPORT(cfggpio, cfggpio cfggpio: <num|value>);
MSH_CMD_EXPORT(cfggpio, cfggpio cfggpio: <num|value>);


